# -*- coding: utf-8 -*-
import pygame

pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("Ex 17.2")
black = pygame.Color(0,0,0)
red = pygame.Color(255,0,0)
green = pygame.Color(0,255,0)
blue = pygame.Color(0,0,255)
bgcolor = black
running = True
while running:
    screen.fill(bgcolor)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_r:
                bgcolor = red
            elif event.key == pygame.K_g:
                bgcolor = green
            elif event.key == pygame.K_b:
                bgcolor = blue
            elif event.key == pygame.K_ESCAPE:
                running = False
    pygame.display.flip()
pygame.quit()
